import { login, login2, visions, uploadUrl } from '../../utils/api.js';
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
Page({
  data: {// 私有数据，可用于模板渲染
    title: '标题',
    toHome: true,
    content: '此功能需要登录使用',
    confirm: '确定',
    cancel: '取消',
    show_loadnote: true,
    onload: 0,
    visionShow: visions(),
    titlename: '详情',
    scienceid: '',
    avatarUrl: defaultAvatarUrl,
    avatar:'',
    nickName:'',
    usermessage: {
      userid: '',
      NickName: '',
      HeadUrl: '',
      openid: '',
      session_key: '',
    }
  },
    onChange(e){
      this.setData({
        nickName: e.detail
      })
    },
    onChooseAvatar(e) {   
      var that=this
      const { avatarUrl } = e.detail
      this.setData({
        avatarUrl,
      })
      wx.uploadFile({        
        filePath: avatarUrl,
        name: 'file',
        url: uploadUrl,
        formData:{
          "type": 'images'
        },
        success: function (res) {
          console.log(JSON.parse(res.data))
          that.setData({
            avatar: JSON.parse(res.data).data.image_url[0]
          })
        },
        fail: function (res) {
          console.log(res)
        }
      })
    },
    close_reminder: function () {
      this.setData({
        show_loadnote: false
      })
      wx.showToast({
        title: '部分功能无法使用',
        icon: 'none',
        success:(res)=>{         
          if(this.data.toHome){
            wx.switchTab({
              url: '/pages/home/home'
            })
          }          
        }
      })
    },
    getUserProfile(e) {    
      if(this.data.visionShow){
        let avatarUrl = this.data.avatar
        let nickName = this.data.nickName
        let useInfo = {
          avatarUrl,
          nickName
        }
      }else{
        login(this.data.toHome)
      }
      
      // this.setData({
      //   show_loadnote: false
      // })
    },
  lifetimes: {

  },
})